package net.sf.webdav;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.InputStream;
import java.security.Principal;
import java.util.Date;

/**
 * Created by minios on 16-1-3.
 */
public class VirtualDirectoryStore implements IWebdavStore {

    private Logger LOG = LoggerFactory.getLogger(VirtualDirectoryStore.class);

    File[] parts = null;

    public VirtualDirectoryStore() {
        parts = File.listRoots();

    }

    @Override
    public void destroy() {

    }

    @Override
    public ITransaction begin(Principal principal) {
        return null;
    }

    @Override
    public void checkAuthentication(ITransaction transaction) {

    }

    @Override
    public void commit(ITransaction transaction) {

    }

    @Override
    public void rollback(ITransaction transaction) {

    }

    @Override
    public void createFolder(ITransaction transaction, String folderUri) {

    }

    @Override
    public void createResource(ITransaction transaction, String resourceUri) {

    }

    @Override
    public InputStream getResourceContent(ITransaction transaction, String resourceUri) {
        return null;
    }

    @Override
    public long setResourceContent(ITransaction transaction, String resourceUri, InputStream content, String contentType, String characterEncoding) {
        return 0;
    }

    @Override
    public String[] getChildrenNames(ITransaction transaction, String folderUri) {


        String[] vd = new String[parts.length];
        for (int i = 0; i < vd.length; i++) {

            vd[i] = parts[i].getAbsolutePath();

        }
        return vd;
    }

    @Override
    public long getResourceLength(ITransaction transaction, String path) {
        return 0;
    }

    @Override
    public void removeObject(ITransaction transaction, String uri) {

    }

    @Override
    public StoredObject getStoredObject(ITransaction transaction, String uri) {
        StoredObject so=new StoredObject();
        so.setFolder(true);
        Date date=new Date();
        so.setLastModified(date);
        so.setCreationDate(date);

        so.setResourceLength(parts.length);
        return so;
    }
}
